<?php
    include "inc_security.php";
    checkAddEdit("edit");
    
    $record_id 		= getValue("record_id", 'int', 'GET')?getValue("record_id", 'int', 'GET'):getValue("record_id", 'int', 'POST');
    $errorMsg = '';
    
    function get_meber($proid){
        $sql = "SELECT * FROM project_user WHERE pru_pro_id = '".$proid."'";
        $db_query = new db_query($sql);
        $profiles_id = array();
        while($puser = mysql_fetch_array($db_query->result)){
            $profiles_id[$puser['pru_user_id']] = $puser['pru_user_id'];
        }
        unset($db_query);
        $menbers = array();
        if(!empty($profiles_id)){
            $sqlp = 'SELECT use_name, use_linkfb, use_id, use_facebook_id, use_avatar, use_email 
                    FROM users 
                    WHERE use_id IN ('.implode(',',$profiles_id).')';
            $db = new DatabaseVcamp($sqlp);
            while($user = mysql_fetch_assoc($db->result)){
                $menbers[$user['use_id']] = $user;
            }
        }

        return $menbers;
    }
    function get_project_info($pro_id){
        $project = array();
        $sql = 'SELECT p.*, cm.cat_name, c.cit_name FROM projects AS p 
                LEFT JOIN categories_multi AS cm ON cm.cat_id = p.pro_cat_id 
                LEFT JOIN city AS c ON p.pro_city = c.cit_id 
                WHERE p.pro_id = \''.$pro_id.'\'';
        $db_query = new db_query($sql);
        $project = mysql_fetch_assoc($db_query->result);
        $sqlpu = 'SELECT use_name, use_linkfb, use_id, use_facebook_id, use_avatar, use_email 
                    FROM users 
                    WHERE use_id = \''.$project['pro_user_id'].'\'';
        $db = new DatabaseVcamp($sqlpu);
        $project['users'] = mysql_fetch_assoc($db->result);
        
        unset($db_query);
        $sqlposition = 'SELECT pp.* FROM project_position AS pp
                WHERE pp.prp_pro_id = \''.$pro_id.'\'';
        $db_query = new db_query($sqlposition);
        $positions = array();
        while($position = mysql_fetch_assoc($db_query->result)){
            $positions[$position['prp_id']] = $position;
        }
        $project['positions'] = $positions;
        $sqlinfo = 'SELECT pi.* FROM project_info AS pi
                WHERE pi.pri_pro_id = \''.$pro_id.'\'';
        
        $db_query = new db_query($sqlinfo);
        $info = array();
        while($item = mysql_fetch_assoc($db_query->result)){
            $info[$item['pri_id']] = $item;
        }
        $project['info'] = $info;
        $project['menbers'] = get_meber($pro_id);
        return $project;
    }
?>

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.1//EN" "http://www.w3.org/TR/xhtml11/DTD/xhtml11.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8"/>
<link href="../../../css/jquery-ui-autocompelete.min.css" rel="stylesheet"/>
<link href="../../../themes/css/admin.css" rel="stylesheet"/>
<?=$load_header?>
<script lang="javascript" src="../../../js/juimin/jquery.ui.core.min.js"></script>
<script lang="javascript" src="../../../js/juimin/jquery.ui.widget.min.js"></script>
<script lang="javascript" src="../../../js/juimin/jquery.ui.position.min.js"></script>
<script lang="javascript" src="../../../js/juimin/jquery.ui.menu.min.js"></script>
<script lang="javascript" src="../../../js/juimin/jquery.ui.autocomplete.min.js"></script>
<script lang="javascript" src="../../../js/custom.js"></script>
<? 
//$myform->checkjavascript();
//$errorMsg .= $myform->strErrorField;

//lay du lieu cua record can sua doi
$project = get_project_info($record_id);
?>
<style type="text/css">
<!--
.sitem{
    border-bottom: 1px solid #CCCCCC;
    border-left: 1px solid #CCCCCC;
    border-right: 1px solid #CCCCCC;
    cursor: pointer;
    margin-left: 5px;
    max-width: 250px;
    padding: 4px 10px;
}
.sitem:first-child{
    border-top: 1px solid #CCCCCC;
    margin-top: 5px;
}
-->
</style>
</head>
<body topmargin="0" bottommargin="0" leftmargin="0" rightmargin="0">
<?php
    //echo '<pre>';print_r($project);echo '</pre>';
?>
<div id="project-info">
    <h1 class="project-name"><?php print $project['pro_name'];?></h1>
    <div class="project-summary">
        <?php print $project['pro_summary'];?>
    </div>
    <h2 class="project-title">Thông tin dự án</h2>
    <ul class="content">
        <li class="rows">
            <span class="label">Người đăng:</span>
            <span class="body"><a class="menname" href="<?php print generate_profile_url($project['users'])?>"><?php print $project['users']['use_name'];?></a></span>
        </li>
        <li class="rows">
            <span class="label">Status:</span>
            <span class="body"><?php print $project['pro_status'];?></span>
        </li>
        <li class="rows">
            <span class="label">Lĩnh vực:</span>
            <span class="body"><?php print $project['cat_name'];?></span>
        </li>
        <li class="rows">
            <span class="label">Website:</span>
            <span class="body"><?php print $project['pro_website'];?></span>
        </li>
        <li class="rows">
            <span class="label">Email:</span>
            <span class="body"><?php print $project['pro_email'];?></span>
        </li>
        <li class="rows">
            <span class="label">Trụ sở:</span>
            <span class="body"><?php print $project['pro_address'];?></span>
        </li>
        <li class="rows">
            <span class="label">Thành phố:</span>
            <span class="body"><?php print $project['cit_name'];?></span>
        </li>
        <li class="rows">
            <span class="label">Quy mô công ty:</span>
            <span class="body"><?php print $project['pro_size'];?></span>
        </li>
    </ul>
    <?php if(!empty($project['menbers'])){ ?>
    <div class="project-menbers">
        <h2 class="project-title">Thành viên dự án</h2>
        <ul class="list-menbers">
        <?php foreach($project['menbers'] as $key => $menber){ ?>
            <li><a class="menname" href="<?php print generate_profile_url($menber)?>"><?php print $menber['use_name'];?></a></li>
        <?php } ?>
        </ul>
    </div>
    <?php } ?>
    <div class="project-jobs">
    <h2 class="project-title">Vị trí dự án</h2>
    <?php foreach($project['positions'] as $key => $jobs){ ?>
        <div class="job-info">
            <h3 class="jobs-title"><?php print $jobs['prp_pos_name']; ?></h3>
            <div class="pro-job-desc"><span class="job-des-title">Mô tả:</span> <?php print $jobs['prp_desc']; ?></div>
            <div class="pro-job-desc"><span class="job-des-title">Yêu cầu:</span> <?php print $jobs['prp_require']; ?></div>
            <div class="pro-job-desc"><span class="job-des-title">Môi trường:</span> <?php print $jobs['prp_place']; ?></div>
            <div class="pro-job-desc"><span class="job-des-title">Quyền lợi:</span> <?php print $jobs['prp_benefits']; ?></div>
        </div>
    <?php } ?>
    </div>
    <?php foreach($project['info'] as $key => $info){ ?>
        <h2 class="project-title"><?php print $info['pri_label']; ?></h2>
        <div class="pro-info-detail"><?php print $info['pri_detail']; ?></div>
    <?php } ?>
    <h2 class="project-title">Thao tác</h2>
    <div class="pro-info-detail">
        <form action="POST">
        <div class="mes-text">
            <h3>Tin nhắn:</h3>
            <textarea class="mes-input" id="mes" name="mes"></textarea>
        </div>
        <div class="actions-check">
        <?php if($project['pro_active'] == 0){?>
            <input type="checkbox" value="1" id="active" name="active"/>
        <?php }else{?>
            <input type="checkbox" value="1" id="active" name="active" checked="checked" />
        <?php } ?>
            <label for="active">Duyệt</label>
        <?php if($project['pro_hot'] == 0){?>
            <input type="checkbox" value="1" id="hot" name="hot"/>
        <?php }else{?>
            <input type="checkbox" value="1" id="hot" name="hot" checked="checked" />
        <?php } ?>
            <label for="hot">Hot</label>
        </div>
        <div class="actions-button">
            <input type="button" value="Submit" class="submit" id="submit-button"/>
            <input type="hidden" value="<?php print $project['pro_id'];?>" id="proid" name="proid"/>
            <input type="hidden" value="<?php print $project['pro_user_id'];?>" id="useid" name="useid"/>
        </div>
        </form>
    </div>
</div>
</body>
</html>